package com.pureut.storage.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pureut.common.security.utils.DictUtils;
import com.pureut.storage.domain.PickingSaleDetail;
import com.pureut.storage.dto.NewPickingSaleDetailDto;
import com.pureut.storage.mapper.PickingSaleDetailMapper;
import com.pureut.storage.service.PickingSaleDetailService;
import com.pureut.system.api.domain.SysDictData;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author: CM
 * @date: 2023/2/2  14:00
 */
@Service
public class PickingSaleDetailServiceImpl extends ServiceImpl<PickingSaleDetailMapper, PickingSaleDetail> implements PickingSaleDetailService {

    @Resource
    PickingSaleDetailMapper pickingSaleDetailMapper;

    /**
     * 销售发货明细列表
     * @param docNum
     * @return
     */
    @Override
    public List<NewPickingSaleDetailDto> getList(String docNum) {
        //获取单据状态字典数据
        List<SysDictData> statusArray = DictUtils.getDictCache("picking_sale_detail_status");
        Map<String, String> statusMap = statusArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 网型
        List<SysDictData> meshTypeArray = DictUtils.getDictCache("sys_of_type");
        Map<String, String> meshTypeMap = meshTypeArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 铺网类型
        List<SysDictData> layingTypeArray = DictUtils.getDictCache("sys_type_net");
        Map<String, String> layingTypeMap = layingTypeArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));


        List<NewPickingSaleDetailDto> list = pickingSaleDetailMapper.getPickDetailList(docNum);

        for (NewPickingSaleDetailDto newPickingSaleDetailDto : list) {
            newPickingSaleDetailDto.setWodStatus(newPickingSaleDetailDto.getWodStatus());
            newPickingSaleDetailDto.setWodStatusDict(statusMap.get(newPickingSaleDetailDto.getWodStatus()));
            newPickingSaleDetailDto.setMaterialNet(meshTypeMap.get(newPickingSaleDetailDto.getMaterialNet()+""));
            newPickingSaleDetailDto.setMaterialNetType(layingTypeMap.get(newPickingSaleDetailDto.getMaterialNetType()+""));

        }
        return list;
    }
}
